﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SipII.Parameter
{
    #region enum

    /// <summary>
    /// 命令标识
    /// </summary>
    public enum enumCmdId
    {
        /// <summary>
        /// 请求停用借书证
        /// </summary>
        BlockPatron = 1,

        /// <summary>
        /// 请求还书
        /// </summary>
        Checkin = 9,

        /// <summary>
        /// 响应还书操作
        /// </summary>
        CheckinResponse = 10,

        /// <summary>
        /// 请求借书
        /// </summary>
        Checkout = 11,

        /// <summary>
        /// 响应借书操作
        /// </summary>
        CheckoutResponse = 12,

        /// <summary>
        /// 请求预约
        /// </summary>
        Hold = 15,

        /// <summary>
        /// 响应预约操作
        /// </summary>
        HoldResponse = 16,

        /// <summary>
        /// 查询图书信息
        /// </summary>
        ItemInformation = 17,

        /// <summary>
        /// 返回图书信息
        /// </summary>
        ItemInformationResponse = 18,

        /// <summary>
        /// 请求更改图书状态
        /// </summary>
        ItemStatusUpdate = 19,

        /// <summary>
        /// 响应更改图书状态操作
        /// </summary>
        ItemStatusUpdateResponse = 20,

        /// <summary>
        /// 查询读者状态
        /// </summary>
        PatronStatus = 23,

        /// <summary>
        /// 返回读者状态
        /// </summary>
        PatronStatusResponse = 24,

        /// <summary>
        /// 启用读者请求
        /// </summary>
        PatronEnable = 25,

        /// <summary>
        /// 响应启用读者操作
        /// </summary>
        PatronEnableResponse = 26,

        /// <summary>
        /// 单本续借请求
        /// </summary>
        Renew = 29,

        /// <summary>
        /// 响应单本续借操作
        /// </summary>
        RenewResponse = 30,

        /// <summary>
        /// 请求结束读者会话
        /// </summary>
        EndPatronSession = 35,

        /// <summary>
        /// 响应结束读者会话操作
        /// </summary>
        EndSessionResponse = 36,

        /// <summary>
        /// 缴费请求
        /// </summary>
        FeePaid = 37,

        /// <summary>
        /// 响应缴费操作
        /// </summary>
        FeePaidResponse = 38,

        /// <summary>
        /// 查询读者信息
        /// </summary>
        PatronInformation = 63,

        /// <summary>
        /// 返回读者信息
        /// </summary>
        PatronInformationResponse = 64,

        /// <summary>
        /// 请求全部续借
        /// </summary>
        RenewAll = 65,

        /// <summary>
        /// 响应全部续借操作
        /// </summary>
        RenewAllResponse = 66,

        /// <summary>
        /// 登录
        /// </summary>
        Login = 93,

        /// <summary>
        /// 响应登录操作
        /// </summary>
        LoginResponse = 94,

        /// <summary>
        /// 请求SC重发命令
        /// </summary>
        RequestScResend = 96,

        /// <summary>
        /// 请求ACS重发命令
        /// </summary>
        RequestAcsResend = 97,

        /// <summary>
        /// 返回ACS状态
        /// </summary>
        AcsStatus = 98,

        /// <summary>
        /// 返回SC状态
        /// </summary>
        ScStatus = 99
    };

    /// <summary>
    /// 字段名称
    /// </summary>
    public enum enumFieldName
    {
        blocked_card_msg,
        cancel,
        charged_items,
        charged_items_limit,
        checksum,
        currency_type,
        current_location,
        due_date,
        email_address,
        end_item,
        expiration_date,
        fee_acknowledged,
        fee_amount,
        fee_identifier,
        fee_limit,
        fee_type,
        fine_items,
        hold_items,
        hold_items_limit,
        hold_pickup_date,
        hold_queue_length,
        hold_type,
        home_address,
        home_phone_number,
        institution_id,
        item_identifier,
        item_properties,
        library_name,
        location_code,
        login_password,
        login_user_id,
        media_type,
        overdue_items,
        overdue_items_limit,
        owner,
        patron_identifier,
        patron_password,
        permanent_location,
        personal_name,
        pickup_location,
        print_line,
        queue_position,
        recall_date,
        recall_items,
        renewed_items,
        screen_message,
        security_inhibit,
        sequence_number,
        sort_bin,
        start_item,
        supported_messages,
        terminal_location,
        terminal_password,
        title_identifier,
        transaction_id,
        unavailable_hold_items,
        unrenewed_items,
        valid_patron,
        valid_patron_password
    }

    /// <summary>
    /// 文献的流通状态
    /// </summary>
    public enum enumCirculationstatus
    {
        /// <summary>
        /// 
        /// </summary>
        other = 1,

        /// <summary>
        /// 
        /// </summary>
        on_order = 2,

        /// <summary>
        /// 
        /// </summary>
        available = 3,

        /// <summary>
        /// 
        /// </summary>
        charged = 4,

        /// <summary>
        /// 
        /// </summary>
        charged1 = 5,

        /// <summary>
        /// 
        /// </summary>
        in_process = 6,

        /// <summary>
        /// 
        /// </summary>
        recalled = 7,

        /// <summary>
        /// 
        /// </summary>
        waiting_on_hold_shelf = 8,

        /// <summary>
        /// 
        /// </summary>
        waiting_to_be_reshelved = 9,

        /// <summary>
        /// 
        /// </summary>
        in_transit_between_library_locations = 10,

        /// <summary>
        /// 
        /// </summary>
        claimed_returned = 11,

        /// <summary>
        /// 
        /// </summary>
        lost = 12,

        /// <summary>
        /// 
        /// </summary>
        missing = 13
    };

    /// <summary>
    /// 货币类型
    /// </summary>
    public enum enumCurrencyType { CNY, USD, GBP, FRF, RUB, CAD, DEM, ITL, ESP, JPY };

    /// <summary>
    /// 收费类型
    /// </summary>
    public enum enumFeeType
    {
        /// <summary>
        /// 其它费用
        /// </summary>
        other_unknown = 1,

        /// <summary>
        /// 行政管理费
        /// </summary>
        administrative = 2,

        /// <summary>
        /// 图书损毁罚款
        /// </summary>
        damage = 3,

        /// <summary>
        /// 超期罚款
        /// </summary>
        overdue = 4,

        /// <summary>
        /// 图书处理费
        /// </summary>
        processing = 5,

        /// <summary>
        /// 租金
        /// </summary>
        rental = 6,

        /// <summary>
        /// 图书证补领费
        /// </summary>
        replacement = 7,

        /// <summary>
        /// 计算机检索费
        /// </summary>
        computer_access_charge = 8,

        /// <summary>
        /// 预约费
        /// </summary>
        hold_fee = 9
    };

    /// <summary>
    /// 保留类型
    /// </summary>
    public enum enumHoldType
    {
        /// <summary>
        /// 其它
        /// </summary>
        other = 1,

        /// <summary>
        /// 任意副本
        /// </summary>
        any_copy_of_a_title = 2,

        /// <summary>
        /// 指定副本
        /// </summary>
        a_specific_copy_of_a_title = 3,

        /// <summary>
        /// 子馆的任意副本
        /// </summary>
        any_copy_at_a_single_branch_or_sublocation = 4
    }

    /// <summary>
    /// 语言类型
    /// </summary>
    public enum enumLanguage
    {
        Unknown = 0,
        English = 1,
        French = 2,
        German = 3,
        Italian = 4,
        Dutch = 5,
        Swedish = 6,
        Finnish = 7,
        Spanish = 8,
        Danish = 9,
        Portuguese = 10,
        Canadian_French = 11,
        Norwegian = 12,
        Hebrew = 13,
        Japanese = 14,
        Russian = 15,
        Arabic = 16,
        Polish = 17,
        Greek = 18,
        Chinese = 19,
        Korean = 20,
        North_American_Spanish = 21,
        Tamil = 22,
        Malay = 23,
        UnitedKingdom = 24,
        Icelandic = 25,
        Belgian = 26,
        Taiwanese = 27
    }

    /// <summary>
    /// 媒体类型
    /// </summary>
    public enum enumMediaType
    {
        other = 0,
        book = 1,
        magazine = 2,
        bound_journal = 3,
        audio_tape = 4,
        video_tape = 5,
        cdrom = 6,
        diskette = 7,
        book_with_diskette = 8,
        book_with_CD = 9,
        book_with_audio_tape = 10
    }

    /// <summary>
    /// 付款方式
    /// </summary>
    public enum enumPaymentType
    {
        cash = 0,
        VISA = 1,
        credit_card = 2,
    }

    /// <summary>
    /// 安全标志
    /// </summary>
    public enum enumSecurityMarker
    {
        other = 0,
        None = 1,
        Tattle_Tape_Security_Strip = 2,
        Whisper_Tape = 3
    }

    /// <summary>
    ///   自助设备状态
    /// </summary>
    public enum enumStatusCode
    {
        SC_unit_is_OK = 0,
        SC_printer_is_out_of_paper = 1,
        SC_is_about_to_shut_down = 2
    }

    #endregion

    public static class Sip2Parameter
    {
        /// <summary>
        /// 消息终止符
        /// </summary>
        public const string MessageTerminator = "\n";

        /// <summary>
        /// 空字符
        /// </summary>
        public const string Nulls = "\x00";

        /// <summary>
        /// 变长字段终止符,可配置
        /// </summary>
        public static string FieldDelimiter = Properties.Settings.Default.FieldDelimiter;

        /// <summary>
        /// "枚举名称-长度"字典
        /// </summary>
        public static Dictionary<string, int> dicEnumCodeLength = new Dictionary<string, int>() { 
            {"enumCmdId",2},
            {"enumCirculationstatus",2},
            {"enumFeeType",2},
            {"enumHoldType",1},
            {"enumLanguage",3},
            {"enumMediaType",3},
            {"enumPaymentType",2},
            {"enumSecurityMarker",2},
            {"enumStatusCode",1}
        };




        /// <summary>
        ///  字段"名称-ID"字典
        /// </summary>
        public static Dictionary<string, string> dicFieldId = new Dictionary<string, string>() {
            {"blocked_card_msg","AL"},
            {"cancel","BI"},
            {"charged_items","AU"},
            {"charged_items_limit","CB"},
            {"checksum","AZ"},
            {"currency_type","BH"},
            {"current_location","AP"},
            {"due_date","AH"},
            {"email_address","BE"},
            {"end_item","BQ"},
            {"expiration_date","BW"},
            {"fee_acknowledged","BO"},
            {"fee_amount","BV"},
            {"fee_identifier","CG"},
            {"fee_limit","CC"},
            {"fee_type","BT"},
            {"fine_items","AV"},
            {"hold_items","AS"},
            {"hold_items_limit","BZ"},
            {"hold_pickup_date","CM"},
            {"hold_queue_length","CF"},
            {"hold_type","BY"},
            {"home_address","BD"},
            {"home_phone_number","BF"},
            {"institution_id","AO"},
            {"item_identifier","AB"},
            {"item_properties","CH"},
            {"library_name","AM"},
            {"location_code","CP"},
            {"login_password","CO"},
            {"login_user_id","CN"},
            {"media_type","CK"},
            {"overdue_items","AT"},
            {"overdue_items_limit","CA"},
            {"owner","BG"},
            {"patron_identifier","AA"},
            {"patron_password","AD"},
            {"permanent_location","AQ"},
            {"personal_name","AE"},
            {"pickup_location","BS"},
            {"print_line","AG"},
            {"queue_position","BR"},
            {"recall_date","CJ"},
            {"recall_items","BU"},
            {"renewed_items","BM"},
            {"screen_message","AF"},
            {"security_inhibit","CI"},
            {"sequence_number","AY"},
            {"sort_bin","CL"},
            {"start_item","BP"},
            {"supported_messages","BX"},
            {"terminal_location","AN"},
            {"terminal_password","AC"},
            {"title_identifier","AJ"},
            {"transaction_id","BK"},
            {"unavailable_hold_items","CD"},
            {"unrenewed_items","BN"},
            {"valid_patron","BL"},
            {"valid_patron_password","CQ"}
        };

        /// <summary>
        /// 获取枚举代码
        /// </summary>
        /// <param name="enumValue">枚举值</param>
        /// <returns></returns>
        public static string GetEnumCode(object enumValue)
        {
            string typename = enumValue.GetType().Name;
            int length = dicEnumCodeLength[typename];
            return ((int)enumValue).ToString("D" + length.ToString());
        }

    }
}
